log using "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files/stata_log_data", text replace

********************************************************************

*******************     DATASET CONSTRUCTION     *******************

********************************************************************

**# CSHAPES DISTANCE DATA
*Identifying direct land borders using CShapes 2.0

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
insheet using "originals/cshapes.csv"

gen neighbours = 1 if mindist == 0

drop if missing(neighbours)
drop if ccode1 == ccode2
drop if year<1989
drop capdist centdist mindist neighbours

rename ccode1 referent
rename ccode2 ccode

sort ccode year

save "temps/cshapes_mod.dta", replace

**# SIPRI MCW DATA
*Preparing SIPRI data on all MCW types for merging

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"

*Converting from .csv to .dta
import delimited "originals/sipri_1950-2024.csv"
save "originals/sipri.dta", replace

* Rename variables to be more descriptive
clear
use "originals/sipri.dta"

foreach v of varlist _all {
	local x : variable label `v'
	local x = strtoname("`x'")
	rename `v' Y`x'
}

rename YRecipient recipient

drop Y_1950_2024 YPercentage_of_total YPercentage YSum_total_years

gen ccode=.
order ccode

do "stata/texttocow.do" //Adding in COW country codes

drop if missing(ccode)

*Countries that share COW codes (eg. Soviet Union and Russia) are separate in original SIPRI data so need to be merged together
collapse (firstnm) Y_1950 Y_1951 Y_1952 Y_1953 Y_1954 Y_1955 Y_1956 Y_1957 Y_1958 Y_1959 Y_1960 Y_1961 Y_1962 Y_1963 Y_1964 Y_1965 Y_1966 Y_1967 Y_1968 Y_1969 Y_1970 Y_1971 Y_1972 Y_1973 Y_1974 Y_1975 Y_1976 Y_1977 Y_1978 Y_1979 Y_1980 Y_1981 Y_1982 Y_1983 Y_1984 Y_1985 Y_1986 Y_1987 Y_1988 Y_1989 Y_1990 Y_1991 Y_1992 Y_1993 Y_1994 Y_1995 Y_1996 Y_1997 Y_1998 Y_1999 Y_2000 Y_2001 Y_2002 Y_2003 Y_2004 Y_2005 Y_2006 Y_2007 Y_2008 Y_2009 Y_2010 Y_2011 Y_2012 Y_2013 Y_2014 Y_2015 Y_2016 Y_2017 Y_2018 Y_2019 Y_2020 Y_2021 Y_2022 Y_2023 Y_2024, by(ccode)

*Originally a wide panel dataset, converting to long
reshape long Y_, i(ccode) j(year)
rename Y_ TIV

*Consistency with COW coding
replace ccode=260 if ccode==255 & year<=1990

save "temps/sipri_mod.dta", replace

**# MERGING CSHAPES AND NEIGHBOURS' SIPRI TIVs
/*
1 = microstates (monaco, liechtenstein, andorra, and san marino) - not included in SIPRI??
2 = no neighbours, either due to no land border or country/data didn't exist in that year
3 = match
*/ 

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_mod.dta"
merge m:1 ccode year using temps/sipri_mod.dta

//drop if (year<1989 | year>=2020)
drop if (year<1989)
keep if _merge == 3
drop _merge

rename ccode neighbour
rename TIV neighbour_TIV

save "temps/cshapes_sipri.dta", replace

**# GENERATING COLLECTIVE IMPORTS
/*
summing up a country's neighbours' TIVs for a particular year. this generates duplicates where the country has multiple neighbours, so dropped the duplicate observations. neighbour ccodes are also no longer necessary as each instance of the referent country should have the same collective TIV
*/

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_sipri.dta"

egen collective_TIV = total(neighbour_TIV), by(referent year)

drop neighbour_TIV neighbour
duplicates drop

rename referent ccode
sort ccode year

save "temps/sipri_coll.dta", replace

**# MERGING CONFLICT COUNTRY SIPRI DATA INTO MAIN DATASET
/*
1 = microstates (monaco, liechtenstein, andorra, and san marino) - not included in SIPRI??
2 = no neighbours, either due to no land border or country/data didn't exist in that year
3 = match
*/ 

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_coll.dta"

merge 1:1 ccode year using temps/sipri_mod.dta

//drop if (year<1989 | year>=2020)
drop if year<1989
keep if _merge == 3
drop _merge

rename TIV self_TIV

replace self_TIV = self_TIV * 100
replace collective_TIV = collective_TIV * 100

gen lncollective_TIV = ln(collective_TIV)
gen lnself_TIV = ln(self_TIV)

save "temps/sipri_coll_self.dta", replace

**# BATTLE RELATED DEATHS
/*
INTRASTATE CONFLICTS ONLY

1 = extrasystemic (state vs non-state outside its own territory)
2 = interstate (state vs state)
3 = intrastate (state vs non-state)
4 = internationalised intrastate (state vs non-state, but there is involvement of foreign govts with troops)
*/

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "originals/BattleDeaths_v24_1_conf.dta"

keep if type_of_conflict == 3

drop dyad_id side_a side_b side_a_id side_b_id side_a_2nd side_b_2nd gwno_a gwno_b gwno_a_2nd gwno_b_2nd incompatibility version gwno_battle location_inc bd_low bd_high type_of_conflict battle_location territory_name

rename gwno_loc ccode

destring ccode, replace

replace ccode = 679 if ccode == 678 & year > 1990

order ccode year bd_best
sort ccode year

collapse (sum) bd_best, by(ccode year)

gen lnbd_best = ln(bd_best)

save "temps/ucdp_bd_mod.dta", replace

**# MERGING BR DEATHS INTO MAIN DATASET
/*
1 = no BR-deaths in that countryyear
2 = islands/out of date range
3 = match
*/

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_coll_self.dta"

merge 1:1 ccode year using temps/ucdp_bd_mod.dta

//drop if (year<1989 | year>=2020)
drop if year<1989
drop if _merge == 2
drop _merge

order ccode year bd_best lnbd_best collective_TIV self_TIV

save "temps/sipri_coll_self_bd.dta", replace

//obs in ucdp only are ISLANDS or where there are coding differences (ie measuring during the year where the country became independent vs the first full cal year)

**# CONTROL VARIABLES
* WORLD ECONOMICS DATAVERSE

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
insheet using "originals/popgdppolity1.csv"

label var polity_p4 "Combined polity score"
label var lnpop_wdi_pw "Population"
label var lngdp_wdi_pw "GDP"
label var lngdppc_wdi_pw "GDP Per Capita"

rename polity_p4 polity
rename lnpop_wdi_pw lnpop
rename lngdp_wdi_pw lngdp
rename lngdppc_wdi_pw lngdppc

save "originals/popgdppolity1.dta", replace

drop country gwno ifscode ifs gwabbrev polity

destring ccode lnpop lngdp lngdppc, replace force 

order ccode year
sort ccode year

duplicates drop
drop if ccode == . //hong kong and macao don't have ccodes

save "temps/controls1.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_coll_self_bd.dta"

merge 1:m ccode year using temps/controls1.dta

drop if (year<1989 | year>=2020)
drop if _merge == 2
drop _merge

save "temps/sipri_coll_self_bd_c1.dta", replace

**# GSDB DATA
clear 
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "originals/GSDB_V4_dyadic.dta"

keep sanctioned_state_iso3 year arms

drop if (sanctioned_state_iso3 == "" | arms == 0)

gen ccode = .
order ccode

do "stata/iso3tocow.do"

drop if missing(ccode)
drop sanctioned_state_iso3

sort ccode year

duplicates drop ccode year, force
drop if (year<1989 | year>=2020)
//drop if year<1989

save "temps/gsdb_arms.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_coll_self_bd_c1.dta"

merge 1:1 ccode year using temps/gsdb_arms.dta

/*
1 = no arms sanctions
2 = islands and coding clashes
3 = match
*/

drop if _merge == 2
drop _merge

save "temps/sipri_gsdb.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_gsdb.dta"

**# YEAR OF CONFLICT

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "originals/UcdpPrioConflict_v24_1.dta" 

destring type_of_conflict, replace
keep if type_of_conflict == 3

destring year, replace
drop if (year<1989 | year>=2019)

rename gwno_loc ccode
destring ccode, replace
replace ccode = 679 if ccode == 678 & year > 1990

drop type_of_conflict

gen eventdate = date(start_date2, "YMD")
format eventdate %td
gen startyr = year(eventdate)
gen duration = year + 1 - startyr

order ccode year
sort ccode year

keep ccode year conflict_id location region startyr duration

collapse (max) duration, by(ccode year)

gen lnDuration = ln(duration)

save "temps/durations.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_gsdb.dta"

merge 1:1 ccode year using temps/durations.dta

drop if _merge == 2
drop _merge

save "temps/sipri_gsdb_dur.dta", replace

**# VDEM

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "originals/vdem.dta"

keep country_name country_text_id year COWcode v2x_polyarchy e_polity2 e_gdppc e_regionpol_6C e_pelifeex v2xed_ed_inpt

drop if (year<1989 | year>=2019)

replace COWcode = 511 if country_text_id == "ZZB" //zanzibar. don't know why its COW code was missing

drop if missing(COWcode)

rename COWcode ccode

save "temps/vdem_mod.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_gsdb_dur.dta"

merge 1:1 ccode year using temps/vdem_mod.dta

drop if _merge == 2
drop _merge

gen lngdppc_v = ln(e_gdppc)

drop if year >= 2019

replace arms = 0 if missing(arms)

save "temps/c1.dta", replace

**# ETHNIC FRACTIONALIZATION

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"

* Convert .csv to .dta
import delimited "originals/epr.csv"
keep countries_gwid year lexclpop
drop if year < 1989
drop if year > 2018
rename countries_gwid ccode
replace ccode = 679 if ccode == 678 & year > 1990 // yemen
replace ccode = 255 if ccode == 260 & year > 1990 // germany
replace ccode = 345 if ccode == 340 & year > 2006 // serbia
save "originals/eprgrow.dta", replace
// Marginalised Ethnic Group (MEG) population as a fraction of ethnically relevant population in this country (exclpo / lpop)

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c1.dta"

merge 1:1 ccode year using originals/eprgrow.dta

drop if _merge == 2
drop country_text_id v2x_polyarchy v2xed_ed_inpt e_pelifeex e_gdppc e_regionpol_6C lngdppc_v _merge

rename duration year_of_conflict
rename lncollective_TIV ln_neigh_MCW
rename lnself_TIV ln_conflict_MCW
rename lnbd_best ln_BR_deaths
rename e_polity2 polity
rename lnpop ln_population
rename lexclpop ethnic
rename lngdppc ln_GDP_pc
rename arms arms_sanctioned

label var ln_BR_deaths "ln(Battle-Related Deaths)"
label var ln_neigh_MCW "ln(Neighbours' MCW Imports)"
label var ln_conflict_MCW "ln(Conflict Country MCW Imports)"
label var ln_population "ln(Population)"
label var ln_GDP_pc "ln(GDP per capita)"
label var arms_sanctioned "Arms Sanction"
label var year_of_conflict "Year of Conflict"
label var polity "Polity IV"
label var ethnic "Ethnic Fractionalisation"

save "temps/c3.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c3.dta"

xtset ccode year, yearly

gen lastyear = 0 if missing(l.ln_BR_deaths)
replace lastyear = 1 if missing(lastyear)
label var lastyear "BR-deaths Present in Prev. Year"

drop if year > 2018

save "temps/c4.dta", replace

****************************************************************

*******************     PAMP (2018) SPEC     *******************

****************************************************************

**# FILTERED SIPRI DATA ACCORDING TO PAMP (2018) FOR ROBUSTNESS CHECK
clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"

* Convert .csv to .dta
import delimited "originals/filteredTIV.csv"
save "originals/sipri_filtered.dta", replace

gen ccode=.
order ccode

rename deliveryyear year

do "stata/texttocow.do" //Adding in COW country codes

drop if missing(ccode)

sort ccode year

collapse (sum) tivdeliveryvalues, by(ccode year)

save "originals/sipri_filtered_collapsed.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c4.dta"

merge 1:1 ccode year using originals/sipri_filtered_collapsed.dta

drop if _merge == 2
drop _merge lnDuration 
drop if year > 2018

rename tivdeliveryvalues self_pampTIV

order ccode year ln_BR_deaths ln_neigh_MCW arms_sanctioned ln_conflict_MCW lastyear year_of_conflict ln_GDP_pc ln_population polity ethnic self_pampTIV self_TIV

save "temps/c5_p1.dta", replace


**# MERGING CSHAPES AND NEIGHBOURS' SIPRI TIVs
/*
1 = microstates (monaco, liechtenstein, andorra, and san marino) - not included in SIPRI??
2 = no neighbours, either due to no land border or country/data didn't exist in that year
3 = match
*/ 

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_mod.dta"
merge m:1 ccode year using originals/sipri_filtered_collapsed.dta

drop if (year<1989 | year>2018)
keep if _merge == 3
drop _merge

rename ccode neighbour
rename tivdeliveryvalues neighbour_TIV

save "temps/cshapes_sipri_filtered.dta", replace


**# GENERATING COLLECTIVE IMPORTS
/*
summing up a country's neighbours' TIVs for a particular year. this generates duplicates where the country has multiple neighbours, so dropped the duplicate observations. neighbour ccodes are also no longer necessary as each instance of the referent country should have the same collective TIV
*/

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_sipri_filtered.dta"

egen collective_pampTIV = total(neighbour_TIV), by(referent year)

drop neighbour_TIV neighbour
duplicates drop

rename referent ccode
sort ccode year

save "temps/sipri_coll_filtered.dta", replace


**# MERGING COLLECTIVE INTO THE DATASET

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c5_p1.dta"

merge 1:1 ccode year using temps/sipri_coll_filtered.dta

drop if _merge == 2
drop _merge

order ccode year ln_BR_deaths ln_neigh_MCW arms_sanctioned ln_conflict_MCW lastyear year_of_conflict ln_GDP_pc ln_population polity ethnic self_pampTIV self_TIV collective_pampTIV collective_TIV

replace self_pampTIV = self_pampTIV * 100
replace collective_pampTIV = collective_pampTIV * 100

gen ln_neigh_PAMP = ln(collective_pampTIV)
gen ln_conflict_PAMP = ln(self_pampTIV)

save "temps/c5_p2.dta", replace

**************************************************************

*******************     PAMP-PLUS SPEC     *******************

**************************************************************

**# PAMP PLUS
clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"

* Convert .csv to .dta
import delimited "originals/filteredTIV_PAMPplus.csv"
save "originals/sipri_filtered_plus.dta", replace

gen ccode=.
order ccode

rename deliveryyear year

do "stata/texttocow.do" //Adding in COW country codes

drop if missing(ccode)

sort ccode year

collapse (sum) tivdeliveryvalues, by(ccode year)

save "originals/sipri_filtered_collapsed_plus.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c5_p2.dta"

merge 1:1 ccode year using originals/sipri_filtered_collapsed.dta

drop if _merge == 2
drop _merge 
drop if year > 2018

rename tivdeliveryvalues self_pampPLUSTIV

order ccode year ln_BR_deaths ln_neigh_MCW arms_sanctioned ln_conflict_MCW lastyear year_of_conflict ln_GDP_pc ln_population polity ethnic self_pampTIV self_pampPLUSTIV self_TIV

save "temps/c5_p3.dta", replace

**# MERGING CSHAPES AND NEIGHBOURS' SIPRI TIVs
/*
1 = microstates (monaco, liechtenstein, andorra, and san marino) - not included in SIPRI??
2 = no neighbours, either due to no land border or country/data didn't exist in that year
3 = match
*/ 

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_mod.dta"
merge m:1 ccode year using originals/sipri_filtered_collapsed_plus.dta

drop if (year<1989 | year>2018)
keep if _merge == 3
drop _merge

rename ccode neighbour
rename tivdeliveryvalues neighbour_TIV

save "temps/cshapes_sipri_filtered_plus.dta", replace

**# GENERATING COLLECTIVE IMPORTS
/*
summing up a country's neighbours' TIVs for a particular year. this generates duplicates where the country has multiple neighbours, so dropped the duplicate observations. neighbour ccodes are also no longer necessary as each instance of the referent country should have the same collective TIV
*/

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/cshapes_sipri_filtered_plus.dta"

egen collective_pampPLUSTIV = total(neighbour_TIV), by(referent year)

drop neighbour_TIV neighbour
duplicates drop

rename referent ccode
sort ccode year

save "temps/sipri_coll_filtered_plus.dta", replace

**# MERGING COLLECTIVE INTO THE DATASET

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c5_p3.dta"

merge 1:1 ccode year using temps/sipri_coll_filtered_plus.dta

drop if _merge == 2
drop _merge

order ccode year ln_BR_deaths ln_neigh_MCW arms_sanctioned ln_conflict_MCW lastyear year_of_conflict ln_GDP_pc ln_population polity ethnic self_pampTIV self_pampPLUSTIV self_TIV collective_pampTIV collective_pampPLUSTIV collective_TIV

replace self_pampPLUSTIV = self_pampPLUSTIV * 100
replace collective_pampPLUSTIV = collective_pampPLUSTIV * 100

gen ln_neigh_PAMPplus = ln(collective_pampPLUSTIV)
gen ln_conflict_PAMPplus = ln(self_pampPLUSTIV)

label var ln_neigh_PAMPplus "ln(Neighbours' MCW Imports)"
label var ln_conflict_PAMPplus "ln(Conflict Country MCW Imports)"

label var ln_neigh_PAMP "ln(Neighbours' MCW Imports)"
label var ln_conflict_PAMP "ln(Conflict Country MCW Imports)"

save "temps/c5_p4.dta", replace

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c5_p4.dta"

xtset ccode year, yearly

gen lag_arms = l.arms_sanctioned
gen lag_gdppc = l.ln_GDP_pc

label var lag_arms "Arms Sanctions, lagged"
label var lag_gdppc "ln(GDP per capita), lagged"

save "temps/c6", replace


log close

log using "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files/stata_log_analysis", text replace

************************************************************

*******************     DATA ANALYSIS    *******************

************************************************************

*****************************************************************

*******************     INTERESTING STATS     *******************

*****************************************************************

**# UN SECURITY COUNCIL P5 TOTAL IMPORTS

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_mod.dta"

keep if (ccode == 2 | ccode == 200 | ccode == 220 | ccode == 365 | ccode == 710)

rename TIV p5_TIV

collapse (sum) p5_TIV, by(year)

save "temps/sipri_p5.dta", replace

**# TOTAL GLOBAL IMPORTS
clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_mod.dta"

collapse (sum) TIV, by(year)

save "temps/sipri_total.dta", replace

**# TOTAL GLOBAL VS UNSC P5 PLOT
clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/sipri_total.dta"

merge 1:1 year using temps/sipri_p5.dta

graph twoway line TIV p5_TIV year, title("Total global MCW imports", span) subtitle("1950-2023", span) ytitle("Total global MCW imports (TIV, millions)") ymtick(0(5000)50000) xtitle("Year") ylabel(0(10000)50000) xmtick(1950(5)2025) xlabel(1950(10)2025) legend(label(1 "All Countries") label(2 "UNSC P5 Only") size(small))
graph export totalglobal.png, replace

//CALCULATING TOP IMPORTERS 1950-2024
**# TOP 20 IMPORTERS

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

collapse (sum) self_pampPLUSTIV, by(ccode)
sort self_pampPLUSTIV
keep in -20/L

********************************************************

*******************     ANALYSIS     *******************

********************************************************

**# "PAMP-PLUS" MCW SPEC

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

*No interaction
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus i.lag_arms i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store ns3_plus
gen analytical_sample_plus_ns = 1 if e(sample)
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus i.lag_arms i.lastyear year_of_conflict if analytical_sample_plus_ns == 1, fe vce(cluster ccode)
est store ns2_plus
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus if analytical_sample_plus_ns == 1, fe vce(cluster ccode)
est store ns1_plus

esttab ns1_plus ns2_plus ns3_plus using nsmodels_plus.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using an extended version of Pamp et al.'s (2018) specification of relevant types of MCW") mtitles("(1)" "(2)" "(3)") nonum nobaselevels eqlabel(none) align(c) label replace

*Interaction
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store s3_plus
gen analytical_sample_plus_s = 1 if e(sample)
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict if analytical_sample_plus_s == 1, fe vce(cluster ccode)
est store s2_plus
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##lag_arms ln_conflict_PAMPplus if analytical_sample_plus_s == 1, fe vce(cluster ccode)
est store s1_plus

esttab s1_plus s2_plus s3_plus using smodels_plus.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using an extended version of Pamp et al.'s (2018) specification of relevant types of MCW") mtitles("(4)" "(5)" "(6)") nonum nobaselevels eqlabel(none) align(c) label replace

**# DESCRIPTIVE STATS

xtsum bd_best ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus arms_sanctioned lastyear year_of_conflict polity ln_GDP_pc ln_population ethnic if analytical_sample_plus_s == 1

**# MUNDLAK SPECIFICATION TEST

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

*No interaction
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus i.lag_arms i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, vce(cluster ccode)
estat mundlak

*Interaction
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, vce(cluster ccode)
estat mundlak


**# MARGINS

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

xtreg ln_BR_deaths c.ln_neigh_PAMPplus##lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)

margins, at(ln_neigh_PAMPplus=(4(0.5)13) lag_arms=(0(1)1)) level(90)
marginsplot, title("Predictive Margins for Model (6)") note("All other variabeles held at their means; 90% Confidence Intervals") ytitle("Linear prediction of ln(Battle-Related Deaths)") xtitle("ln(Neighbour MCW Imports)")
graph export marginsgraph.png, replace

margins, at(ln_neigh_PAMPplus=10.67809 lag_arms=(0(1)1)) level(90)

****************************************************************

*******************     ROBUSTNESS TESTS     *******************

****************************************************************

**# SIPRI ALL MCW TYPES

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

*No interaction
xtreg ln_BR_deaths ln_neigh_MCW ln_conflict_MCW i.lag_arms i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store ns3_full
gen analytical_sample_full_ns = 1 if e(sample)
xtreg ln_BR_deaths ln_neigh_MCW ln_conflict_MCW i.lag_arms i.lastyear year_of_conflict if analytical_sample_full_ns == 1, fe vce(cluster ccode)
est store ns2_full
xtreg ln_BR_deaths ln_neigh_MCW ln_conflict_MCW if analytical_sample_full_ns == 1, fe vce(cluster ccode)
est store ns1_full

esttab ns1_full ns2_full ns3_full using nsmodels_full.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using all types of MCW recorded by SIPRI (2025)") mtitles("(13)" "(14)" "(15)") nonum nobaselevels eqlabel(none) align(c) label replace

*Interaction
xtreg ln_BR_deaths c.ln_neigh_MCW##lag_arms ln_conflict_MCW i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store s3_full
gen analytical_sample_full_s = 1 if e(sample)
xtreg ln_BR_deaths c.ln_neigh_MCW##lag_arms ln_conflict_MCW i.lastyear year_of_conflict if analytical_sample_full_s == 1, fe vce(cluster ccode)
est store s2_full
xtreg ln_BR_deaths c.ln_neigh_MCW##lag_arms ln_conflict_MCW if analytical_sample_full_s == 1, fe vce(cluster ccode)
est store s1_full

esttab s1_full s2_full s3_full using smodels_full.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using all types of MCW recorded by SIPRI (2025)") mtitles("(16)" "(17)" "(18)") nonum nobaselevels eqlabel(none) align(c) label replace

**# PAMP (2018) MCW SPEC

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

*No interaction
xtreg ln_BR_deaths ln_neigh_PAMP ln_conflict_PAMP i.lag_arms i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store ns3_pamp
gen analytical_sample_pamp_ns = 1 if e(sample)
xtreg ln_BR_deaths ln_neigh_PAMP ln_conflict_PAMP i.lag_arms i.lastyear year_of_conflict if analytical_sample_pamp_ns == 1, fe vce(cluster ccode)
est store ns2_pamp
xtreg ln_BR_deaths ln_neigh_PAMP ln_conflict_PAMP if analytical_sample_pamp_ns == 1, fe vce(cluster ccode)
est store ns1_pamp

esttab ns1_pamp ns2_pamp ns3_pamp using nsmodels_pamp.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using Pamp et al.'s (2018) original specification of relevant types of MCW") mtitles("(7)" "(8)" "(9)") nonum nobaselevels eqlabel(none) align(c) label replace

*Interaction
xtreg ln_BR_deaths c.ln_neigh_PAMP##i.lag_arms ln_conflict_PAMP i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, fe vce(cluster ccode)
est store s3_pamp
gen analytical_sample_pamp_s = 1 if e(sample)
xtreg ln_BR_deaths c.ln_neigh_PAMP##i.lag_arms ln_conflict_PAMP i.lastyear year_of_conflict if analytical_sample_pamp_s == 1, fe vce(cluster ccode)
est store s2_pamp
xtreg ln_BR_deaths c.ln_neigh_PAMP##i.lag_arms ln_conflict_PAMP if analytical_sample_pamp_s == 1, fe vce(cluster ccode)
est store s1_pamp

esttab s1_pamp s2_pamp s3_pamp using smodels_pamp.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Country-fixed effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using Pamp et al.'s (2018) original specification of relevant types of MCW") mtitles("(10)" "(11)" "(12)") nonum nobaselevels eqlabel(none) align(c) label replace

**# RANDOM EFFECTS W/ PAMP-PLUS

clear
cd "/Users/alex/Documents/0University/0Modules/Year 4/PIED3769 Q Diss/Data/files"
use "temps/c6.dta"

xtset ccode year, yearly

*No interaction
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus i.lag_arms i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, re vce(cluster ccode)
est store ns3_plus_re
gen analytical_sample_plus_ns_re = 1 if e(sample)
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus i.lag_arms i.lastyear year_of_conflict if analytical_sample_plus_ns_re == 1, re vce(cluster ccode)
est store ns2_plus_re
xtreg ln_BR_deaths ln_neigh_PAMPplus ln_conflict_PAMPplus if analytical_sample_plus_ns_re == 1, re vce(cluster ccode)
est store ns1_plus_re

esttab ns1_plus_re ns2_plus_re ns3_plus_re using nsmodels_plus_re.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Random-effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using an extended version of Pamp et al.'s (2018) specification of relevant types of MCW") mtitles("(19)" "(20)" "(21)") nonum nobaselevels eqlabel(none) align(c) label replace

*Interaction
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##i.lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict polity lag_gdppc ln_population ethnic, re vce(cluster ccode)
est store s3_plus_re
gen analytical_sample_plus_s_re = 1 if e(sample)
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##i.lag_arms ln_conflict_PAMPplus i.lastyear year_of_conflict if analytical_sample_plus_s_re == 1, re vce(cluster ccode)
est store s2_plus_re
xtreg ln_BR_deaths c.ln_neigh_PAMPplus##i.lag_arms ln_conflict_PAMPplus if analytical_sample_plus_s_re == 1, re vce(cluster ccode)
est store s1_plus_re

esttab s1_plus_re s2_plus_re s3_plus_re using smodels_plus_re.tex, booktabs se ar2(a2) b(a2) star(* 0.10 ** 0.05 *** 0.01) title("Random-effects linear regression models on ln(Battle-Related Deaths per year) with clustered standard errors, using an extended version of Pamp et al.'s (2018) specification of relevant types of MCW") mtitles("(22)" "(23)" "(24)") nonum nobaselevels eqlabel(none) align(c) label replace

log close
